import QtQuick 2.0
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.14
import QtMultimedia 5.14
import "../component/"

Item {
    id:root
     anchors.leftMargin: 30
     anchors.rightMargin: 30
     anchors.topMargin: 30
     anchors.bottomMargin: 45

     property var list : printControl.fileList

    //设置音频
    MediaPlayer {
        id: playMusic
        playbackRate: 2
        source: "qrc:/music/click2.mp3"
    }

    Rectangle{
        anchors.fill: parent
        color: '#CECDCD'

        ColumnLayout{
            anchors.fill: parent
            spacing: 0
            TabBar {    //点击相应的按钮实现切换
                id: bar
                property int tabInx: 0
                TabButton {
                    id:usdTabBtn
                    font.pixelSize: 20
                    width: root.width / 8
                    padding: 35
                    down: true
                    background: Rectangle{
                        color: bar.tabInx == 0 ? '#1989FA' : '#C0C0C0'
                        border.width: 0
                        RowLayout{
                            anchors.fill: parent
                            spacing: 0
                            Image {
                                id: usbImg
                                source: "qrc:/imgs/usb.png"
                                Layout.leftMargin: 30
                            }
                            Text {
                                id: usbTest
                                text: qsTr("USB")
                                font.pixelSize: 18
                                color: bar.tabInx == 0 ? '#FFF' : '#000'
                                Layout.rightMargin: 30
                                Layout.alignment: Qt.AlignHCenter | Qt.AlignCenter
                            }
                        }
                    }
                    onClicked: {
                        bar.tabInx = 0
                        printControl.getUSB_FileDir()
                    }
                }

                TabButton {
                    font.pixelSize: 20
                    width: root.width / 8
                    down: true
                    background: Rectangle{
                        anchors.fill: parent
                        color: bar.tabInx == 1 ? '#1989FA' : '#C0C0C0'
                        border.width: 0

                        RowLayout{
                            anchors.fill: parent
                            anchors.centerIn: parent
                            Image {
                                id: wifiImg
                                source: "qrc:/imgs/wifi.png"
                                Layout.leftMargin: 30
                            }
                            Text {
                                id: wifiText
                                text: qsTr("Wifi")
                                font.pixelSize: 18
                                color: bar.tabInx == 1 ? '#FFF' : '#000'
                                Layout.rightMargin: 30
                                Layout.alignment: Qt.AlignHCenter | Qt.AlignCenter
                            }
                        }
                    }
                    onClicked: {
                        bar.tabInx = 1
                        printControl.getWifi_FileDir()
                    }
                }
            }

            Rectangle{
                id:innerRec
                Layout.fillWidth: true
                Layout.fillHeight: true
                color: "white"

                GridView{
                    id:gridView
                    cellWidth:90
                    cellHeight:100
                    anchors.fill: parent
                    anchors.topMargin: 10
                    anchors.leftMargin: 20
                    model: printControl.fileList
                    clip:true  // 超出边界的进行裁剪，即不显示，默认为false
                    boundsBehavior:  Flickable.StopAtBounds  // 滑动不超出父框的大小
                    delegate:ExFileItem{
                        id:img
                        name: modelData["name"]
                        type: modelData["type"]
                    }

                    ScrollBar.vertical: ScrollBar {
                        parent: gridView.parent    //设置另一个父级
                        anchors.top: gridView.top
                        anchors.right: gridView.right
                        anchors.bottom: gridView.bottom
                    }
                }
            }
        }

        Rectangle{
            implicitHeight: selectIcon.height + 10
            width: 120 //180
            color: '#c6c6c6'
            radius: 8
            anchors.bottom: parent.bottom
            anchors.bottomMargin: 10
            anchors.horizontalCenter: parent.horizontalCenter

            RowLayout{
                anchors.fill: parent
                anchors.leftMargin: 5
                anchors.rightMargin: 5

                /*Rectangle{
                    Layout.fillWidth: true
                    Layout.fillHeight: true
                    color: 'transparent'
                    Image {
                        id:selectIcon
                        anchors.centerIn: parent
                        source: "qrc:/imgs/select.png"
                    }

                    MouseArea {
                         anchors.fill: parent
                         onPressed: {
                             //playMusic.play();
                             parent.scale*=.9
                         }
                         onReleased: {
                             parent.scale/=.9
                         }
                     }
                }*/

                Rectangle{
                    Layout.fillWidth: true
                    Layout.fillHeight: true
                    color: 'transparent'
                    Image {
                        id:selectIcon
                        anchors.centerIn: parent
                        source: "qrc:/imgs/print.png"
                    }

                    MouseArea {
                         anchors.fill: parent
                         onPressed: {
                             //playMusic.play();
                             parent.scale*=.9
                             printControl.getUnPrintFiles()
                             addPrintWorkBox.open();
                         }
                         onReleased: {
                             parent.scale/=.9
                         }
                     }
                }

                Rectangle{
                    Layout.fillWidth: true
                    Layout.fillHeight: true
                    color: 'transparent'
                    Image {
                        anchors.centerIn: parent
                        source: "qrc:/imgs/delete.png"
                    }

                    MouseArea {
                         anchors.fill: parent
                         onPressed: {
                             //playMusic.play();
                             parent.scale*=.9
                             printControl.getPrintWorkList();
                             deletePrintWorkBox.open()
                         }
                         onReleased: {
                             parent.scale/=.9
                         }
                     }
                }
            }
        }
    }

    ExPopSelectFileBox{
        id:addPrintWorkBox
        title: "添加任务"
        btnName: "添 加"
        listModel: printControl.curFileslist
        anchors.centerIn: root
    }

    ExPopSelectFileBox{
        id:deletePrintWorkBox
        title: "删除任务"
        type:"delete"
        btnName: "删 除"
        listModel: printControl.taskFilesList
        anchors.centerIn: root
    }
}
